<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {

    // pc端后台登录验证 liuq 04 24 
	
    public function index(){
	
	
		$this->display();
		
    }
	
	public function sendAdminValid(){
	    $config = require( __PHYSICS__."/Common/Conf/valid_admin.php");
		if(!$config['codeSet'])unset($config['codeSet']);
		if(!$config['zhSet'])unset($config['zhSet']);
	
		$Verify = new \Think\Verify($config);
		$Verify->entry();
	}
	

	
	public function userLogin(){
	
		$username = I('username');
		$password = I('password');
		
		
		$config = require( __PHYSICS__."/Common/Conf/valid_admin.php");
		$verify = new \Think\Verify($config);
		$valid = I('valid');
		$res = $verify->check($valid);
		if( $res != true ){
		     $data['info'] = '验证码错误';
			 $data['status'] = 106;
			 $this->ajaxReturn($data);
	    }else{
		    
			if( empty($username) || empty($password) ){
		    $data['info'] = '请您完善登录信息';
			$data['status'] = 109;
			$this->ajaxReturn($data);
	    	}
		 
		   $isset_info = M('Administrator')->where('username="'.$username.'"')->field('password, id')->find();
		   if($isset_info){
				 if( md5($password) == $isset_info['password'] ) {
				   
	                                  session('admin_user_name',$username);
					  session('admin_user_id',$isset_info['id']);
					  $data['info'] = '登录成功';
					  $data['status'] = 100;
					    
					  $this->ajaxReturn($data);
					}else{
					  $data['info'] = '密码错误';
					  $data['status'] = 107;
					  $this->ajaxReturn($data);
					}
		   
		   }else{
		            $data['info'] = '用户名不存在';
			        $data['status'] = 108;
			        $this->ajaxReturn($data);
		    }
		 
     }
		
}
	
	public function userlogout(){
		  
		  //session('admin_user_id',null);
                  session('admin_user_name',null);
		  redirect(U('Login/index'));
	}
	
	
	
	
	
	
	
		
	
	
}